package com.jy.app.lib.base;

import android.content.Context;

import java.util.Date;

/**
 * Created by jan on 2016/9/27.
 */

public class TokenConfig extends BaseConfig {
    //token令牌
    public static final String KEY_TOKEN = "KEY_TOKEN_NAME";
    //用户名
    public static final String KEY_USERNAME = "key_username";
    //用户密码
    public static final String KEY_PWD = "key_password";
    //app包名
    public static final String KEY_TIME = "key_time";
    //token失效时间
    public static final String KEY_TOKEN_TIME = "key_tokentime";

    public TokenConfig(Context context, String sharedPreferencesName) {
        super(context, sharedPreferencesName);
    }
    public TokenConfig(Context context) {
        super(context, "TokenConfig");
    }

    public void setToken(String token){
        setString(KEY_TOKEN,token);
    }

    public String getToken(){
        return getString(KEY_TOKEN,"");
    }

    public void setUserName(String userName){
        setString(KEY_USERNAME,userName);
    }

    public String getUserName(){
        return getString(KEY_USERNAME,"");
    }

    public void setPassword(String password){
        setString(KEY_PWD,password);
    }

    public String getPassword(){
        return getString(KEY_PWD,"");
    }

    public void setTime(Long time){
        setLong(KEY_TIME,time+getTokenTime());
    }

    public void resetTime(){
        setTime(new Date().getTime());
    }

    public long getTime(){
        return getLong(KEY_TIME,0L);
    }
    public void setTokenTime(Long time){
        if(time==0){
            time = Constants.TOKEN_TIME;
        }
        setLong(KEY_TOKEN_TIME,time);
    }
    public long getTokenTime(){
        return getLong(KEY_TOKEN_TIME,Constants.TOKEN_TIME);
    }
}
